package Objetos;

import java.awt.List;
import java.io.Serializable;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.SQLException;
import java.util.ArrayList;



public class Aviones extends Conn implements Serializable {
	private int idAvion;
	private String avion;
	private int capacidad;

	public Aviones(){
		
	}
	public Aviones(int id, int capacidad, String avion) {
		this.idAvion = id;
		this.avion = avion;
		this.capacidad = capacidad;
		
	}
	public int getIdavion(){
		return idAvion;
	}

	public String toString(){
		return this.avion;
	}
	
	public String getAvion(){
		return this.avion;		
	}
	
	public int getCapacidad(){
		return this.capacidad;		
	}
	
	
public ArrayList<Aviones> obtenerAviones() throws SQLException{
		
		Connection conn = null;	
		
		ArrayList<Aviones> lAvion = new	ArrayList<Aviones>();	
			try{
				Conn c = new Conn();
				Connection connec = null;
				connec = DriverManager.getConnection(c.getHost() + c.getDbName(), c.getUser(), c.getPass());
						
				Statement st = connec.createStatement();				
				
				ResultSet rs = st.executeQuery("select idAvion, avion, capacidad from aviones");
				Aviones avion;
				while(rs.next()){
					avion = new Aviones(rs.getInt("idAvion"), rs.getInt("capacidad"), rs.getString("avion"));
					lAvion.add(avion);
				}		
			
			
		}catch(SQLException e ){
			e.printStackTrace();
		}
		return lAvion;				
	}	

	public void insertarAvion(Aviones avion){
		 try {
			 Conn c = new Conn();
				Connection connec = null;
				connec = DriverManager.getConnection(c.getHost() + c.getDbName(), c.getUser(), c.getPass());
				Statement st = connec.createStatement();
				
	          st.executeUpdate("insert into aviones(avion, capacidad) values ('"+avion.getAvion()+"',"+avion.getCapacidad()+")");
	          connec.close();        
	          
	        } catch(SQLException e){
	        	e.printStackTrace();
	        }
		
	}
	
	
	
	

	
}
